﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Jzy.Workflow.Snap;
using Frame.Lib.Data;
using Frame.Lib.Core.Base;

namespace Jzy.Workflow.Form
{
    public class FlowFormBO : CommonOperate<FlowFormInfo>
    {
        private FlowFormDAL _flowForm;

        protected override BaseDAL DAL
        {
            get
            {
                return _flowForm;
            }
        }

        public FlowFormBO()
        {
            _flowForm = new FlowFormDAL();            
        }

        public FlowFormBO(DBHelper db):this()
        {
            _flowForm.dbOper = base.dbOper = db;
        }

        public override FlowFormInfo GetInfo(object id)
        {
            FlowFormInfo info = base.GetInfo(id);
            info.GetSnapInfo = tempID => (new FlowSnapBO(base.dbOper)).GetInfo(tempID);
            return info;
        }       



        /// <summary>
        /// 设置表单在流转中的当前流转到的节点，如果是多分支流转，有可能会停流在多个节点上。
        /// </summary>
        /// <param name="forms"></param>
        public void SetCurrentNodes(List<FlowFormInfo> forms)
        {
            Dictionary<int,string> nodes = _flowForm.GetCurrentNodes(forms);

            foreach (FlowFormInfo form in forms)
            {
                if (form.State != (int)FormState.已结束 && form.State != (int)FormState.已归档)
                {
                    form.CurrentNodeName = nodes[form.ID];
                }
            }

        }



        public void SetState(int id, FormState formState)
        {
            _flowForm.SetState(id, formState);
        }

        //public List<FlowFormInfo> GetList(IEnumerable<int> ids)
        //{
        //    return _flowForm.GetList(ids);
        //}
    }
}
